﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace JetRetail
{
    public partial class AddDiscountCardForm : Form
    {
        JetRetailDB DB;

        public AddDiscountCardForm(JetRetailDB DB)
        {
            this.DB = DB;

            InitializeComponent();
        }

        void ValidateInfo()
        {
            bool bEnabled = true;

            if (Buyer.Text == "") bEnabled = false;
            else if ((Card.Text == "")||(Card.Text[0] != '0')) bEnabled = false;
            //else if ((UseFixedDiscount.Checked == true) && (Discount.Text == "")) bEnabled = false;
            else if (Phone.Text == "") bEnabled = false;

            OK.Enabled = bEnabled;
        }

        private void Buyer_TextChanged(object sender, EventArgs e)
        {
            ValidateInfo();
        }

        private void Card_TextChanged(object sender, EventArgs e)
        {
            ValidateInfo();
        }

        /*private void UseFixedDiscount_CheckedChanged(object sender, EventArgs e)
        {
            if (UseFixedDiscount.Checked == false)
            {
                Discount.Text = "";
                Discount.Enabled = false;
            }
            else
            {
                Discount.Enabled = true;
                Discount.Focus();
            }

            ValidateInfo();
        }

        private void Discount_TextChanged(object sender, EventArgs e)
        {
            ValidateInfo();
        }*/

        private void OK_Click(object sender, EventArgs e)
        {
            try
            {
                //DB.ДобавитьПокупателя(Buyer.Text, Card.Text, false, 0, Phone.Text);

                Close();
            }
            catch (Exception e2)
            {
                MessageBox.Show(e2.Message, "Jet-Розница", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void Phone_TextChanged(object sender, EventArgs e)
        {
            ValidateInfo();
        }
    }
}